package com.hopes.bizz.risk.common.service;

import com.hopes.bizz.risk.control.mapper.RiskObjectMapper;
import com.hopes.bizz.risk.control.mapper.RiskUnitEventMapper;
import com.hopes.bizz.risk.control.mapper.RiskUnitMapper;
import com.hopes.bizz.risk.hid.mapper.RiskHidCheckListConfigMapper;
import com.hopes.bizz.risk.hid.mapper.RiskHidCheckPlanMapper;
import com.hopes.bizz.risk.integral.mapper.RiskIntegralExchangeMapper;
import com.hopes.bizz.risk.integral.mapper.RiskIntegralGoodsMapper;
import com.hopes.bizz.risk.setting.mapper.RiskSafetyWarningLabelMapper;
import com.hopes.bizz.risk.transfer.bean.entity.RiskTransferAuthEntity;
import com.hopes.bizz.risk.transfer.service.RiskTransferAuthService;
import com.hopes.boss.admin.api.entity.SysDictItem;
import com.hopes.boss.admin.api.resolver.DictResolver;
import com.hopes.boss.admin.api.resolver.enums.AdminDictEnum;
import com.hopes.boss.common.service.TableDictService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author daijie
 * @version 1.0
 * @date 2023/7/18 16:51
 * @Description:
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class RiskDictServiceImpl implements TableDictService {

    private final RiskObjectMapper riskObjectMapper;

    private final RiskUnitMapper riskUnitMapper;

    private final RiskUnitEventMapper riskUnitEventMapper;

    private final RiskIntegralGoodsMapper riskIntegralGoodsMapper;

    private final RiskIntegralExchangeMapper riskIntegralExchangeMapper;

    private final RiskHidCheckListConfigMapper riskHidCheckListConfigMapper;

    private final RiskHidCheckPlanMapper riskHidCheckPlanMapper;

    private final RiskSafetyWarningLabelMapper riskSafetyWarningLabelMapper;

    private final RiskTransferAuthService riskTransferAuthService;


    public List<SysDictItem> listRiskObjectAsDict() {
        return riskObjectMapper.labelValueList();
    }

    public List<SysDictItem> listRiskObjectCodeAsDict() {
        return riskObjectMapper.labelValueListCode();
    }

    public List<SysDictItem> listRiskUnitAsDict() {
        return riskUnitMapper.labelValueList();
    }

    public List<SysDictItem> listRiskUnitEventAsDict() {
        return riskUnitEventMapper.labelValueList();
    }

    public List<SysDictItem> riskIntegralGoodsMapper() {
        return riskIntegralGoodsMapper.labelValueList();
    }

    public List<SysDictItem> queryEventAndValueAsLabelValue() {
        return riskIntegralExchangeMapper.labelValueList();
    }

    public List<SysDictItem> listRiskSafetyWarningAsDict() {
        return riskSafetyWarningLabelMapper.labelValueList();
    }

    public List<SysDictItem> listRiskHidCheckListAsDict() {
        return riskHidCheckListConfigMapper.labelValueList();
    }

    public List<SysDictItem> listRiskHidCheckListPlanAsDict() {
        return riskHidCheckPlanMapper.labelValueList();
    }


    public List<SysDictItem> listRiskOrgAsDict() {
        List<RiskTransferAuthEntity> riskOrgList = riskTransferAuthService.lambdaQuery()
                .eq(RiskTransferAuthEntity::getUse, Boolean.TRUE)
                .select(RiskTransferAuthEntity::getOrgId)
                .list();

        return riskOrgList.stream().map(riskOrg -> {
            Long orgId = riskOrg.getOrgId();
            SysDictItem sysDictItem = new SysDictItem();
            sysDictItem.setId(orgId);
            sysDictItem.setCode(orgId.toString());
            sysDictItem.setName(DictResolver.getItemLabelByValue(AdminDictEnum.sys_company, orgId));
            return sysDictItem;
        }).collect(Collectors.toList());
    }

}
